//
//  HJPayBillCell.m
//  KaiChat
//
//  Created by lx on 2023/12/22.
//

#import "HJPayBillCell.h"

@interface HJPayBillCell()

@property (nonatomic, weak) UILabel *timeLabel;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UIImageView *stateImageView;
@property (nonatomic, weak) UILabel *contentLabel;
@property (nonatomic, weak) UIImageView *arrowImageView;
@property (nonatomic, weak) UILabel *billDetailsLabel;

@end


@implementation HJPayBillCell


- (void)settingSubView {
    [super settingSubView];
    
    
    self.backgroundColor = UIColor.tj_F6F6F6Color;
    
    UILabel *timeLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(12) color:UIColor.tj_BEBDCAColor title:nil textAlignment:NSTextAlignmentLeft];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(36);
        make.top.offset(0);
        make.centerX.offset(0);
    }];
    
    UIView *tj_contentView = [UIView addToView:self.contentView];
    tj_contentView.addCornerRadius(10);
    tj_contentView.clipsToBounds = YES;
    tj_contentView.backgroundColor = UIColor.whiteColor;
    [tj_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(leftRightMargin);
        make.top.equalTo(timeLabel.mas_bottom);
        make.bottom.offset(0);
    }];
    
    UIView *topView = [UIView addToView:tj_contentView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.inset(0);
        make.height.offset(40);
    }];
    
    UIImageView *stateImageView = [UIImageView addToView:topView];
    [stateImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.centerY.offset(0);
        make.height.width.offset(20);
    }];
    
    UILabel *titleLabel = [UILabel lableWithSuperView:topView font:UIFontMake(12) color:UIColor.tj_868391Color title:nil textAlignment:NSTextAlignmentLeft];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(stateImageView.mas_right).offset(8);
        make.centerY.equalTo(stateImageView);
    }];
    
    UILabel *contentLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    contentLabel.numberOfLines = 0;
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(15);
        make.top.equalTo(topView.mas_bottom);
    }];
    
    UIImageView *arrowImageView = [UIImageView addToView:tj_contentView];
    arrowImageView.image = [UIImage imageNamed:@"pay_bill_arrow"];
    [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(15);
        make.bottom.inset(13);
        make.width.height.offset(12);
    }];
    
    UILabel *billDetailsLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(12) color:UIColor.tj_868391Color title:@"Bill details" textAlignment:NSTextAlignmentLeft];
    [billDetailsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(arrowImageView.mas_left).inset(6);
        make.centerY.equalTo(arrowImageView);
    }];
    
    _billDetailsLabel = billDetailsLabel;
    _arrowImageView = arrowImageView;
    _stateImageView = stateImageView;
    _titleLabel = titleLabel;
    _timeLabel = timeLabel;
    _contentLabel = contentLabel;
}

- (void)setModel:(HJPayBillModel *)model {
    _model = model;
    
    if (model.clickEvent == 102 || model.clickEvent == 200) {
        _arrowImageView.hidden = NO;
        _billDetailsLabel.hidden = NO;
    } else {
        _arrowImageView.hidden = YES;
        _billDetailsLabel.hidden = YES;
    }
    
    _stateImageView.image = [UIImage imageNamed:model.iconName];
    _contentLabel.attributedText = [model.content titleMargin:3 alignment:NSTextAlignmentLeft];
    _titleLabel.text = model.title;
    _timeLabel.text = [[NSDate dateWithTimeIntervalSince1970:[model.timestamp integerValue] / 1000] stringWithFormat:@"yyyy/MM/dd HH:mm"];
    
}


@end
